﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Helpers;
using System.Web.Mvc;
using DotNet.Configuration;
using DotNet.Mvc;
using DotNet.Utility;
using XNWebAPI.Models;
using XNWebService;

namespace XNWebAPI.Controllers
{
    public class SystemController : JsonController
    {
        public ActionResult GetVersionNumber()
        {
            string path = Server.MapPath("~/app_version.json");
            var result = System.IO.File.ReadAllText(path);
            return new JsonStringResult(result);
        }

        public ActionResult GetPermissions()
        {
            string path = Server.MapPath("~/app_permissions.json");
            var result = System.IO.File.ReadAllText(path);
            return new JsonStringResult(result);
        }

        public ActionResult GetIOSPermissions()
        {
            string path = Server.MapPath("~/app_ios_permissions.json");
            var result = System.IO.File.ReadAllText(path);
            return new JsonStringResult(result);
        }

        [HttpGet]
        public ActionResult GetConfigModel()
        {
            JsonDataFile<Dictionary<string, string>> d = new JsonDataFile<Dictionary<string, string>>("conf.json");
            return Json(d.Data);
        }

        [HttpPost]
        public ActionResult SetConfigModel()
        {
            JsonDataFile<Dictionary<string, string>> d = new JsonDataFile<Dictionary<string, string>>("conf.json");
            //d.Data = conf;
            foreach (string item in Request.Form.Keys)
            {
                d.Data[item] = Request.Form[item];
            }
            d.Save();
            return Json(new JsonMessage(true));
        }



        [HttpGet]
        public ActionResult GetSensitiveWordModel()
        {
            JsonDataFile<Dictionary<string, string>> d = new JsonDataFile<Dictionary<string, string>>("SensitiveWord.json");
            return Json(d.Data);
        }

        [HttpPost]
        public ActionResult SetSensitiveWordModel()
        {
            JsonDataFile<Dictionary<string, string>> d = new JsonDataFile<Dictionary<string, string>>("SensitiveWord.json");
            foreach (string item in Request.Form.Keys)
            {
                d.Data[item] = Request.Form[item];
            }
            d.Save();
            //刷新正则表达式
            SensitiveWord.ReSetRegex();
            return Json(new JsonMessage(true));
        }


        /// <summary>
        /// 读取注册协议内容接口
        /// </summary>
        /// <param name="id">标题id</param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult GetRegProtocol(string titleId)
        {
            return Json(RegProtocolService.GetRegProtocol(titleId));
        }


    }
}